home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / GENetReleaseƒ / Extras / GUtilities.c next >
Text File  |  1994-03-07  |  2KB  |  115 lines

  1. /*
  2.     GUtilities.c
  3.     
  4.     General-purpose utility routines
  5.     
  6. */
  7.  
  8. #include "GUtilities.h"
  9.  
  10. //Globals
  11. Str255        gAppName;
  12. OSType        gSignature;
  13. short        gAppResRef;
  14. Boolean        gInBackground = false;
  15.  
  16. Handle    GetAppIndResource(ResType theType, short index, OSErr *err)
  17. {
  18. #pragma unused (err)
  19.  
  20.     short    savedResFile;
  21.     Handle    returnHandle;
  22.     
  23.     savedResFile = CurResFile ();
  24.     UseResFile (gAppResRef);
  25.     returnHandle = Get1IndResource(theType, index);
  26.     UseResFile (savedResFile);
  27.     return (returnHandle);
  28. }
  29.  
  30. void InitSystem( short mbCount )
  31. {
  32.     short counter;
  33.     Handle    apParam;
  34.     Handle    bndlResource;
  35.     OSErr    err;
  36.     
  37.     for (counter = 0; counter < mbCount; counter++)
  38.         MoreMasters();
  39.     InitGraf(&qd.thePort);
  40.     InitFonts();
  41.     InitWindows();
  42.     TEInit();
  43.     InitMenus();
  44.     InitDialogs(0L);
  45.     DrawMenuBar();
  46.     FlushEvents(everyEvent,0L);
  47.     InitCursor();
  48.     InitAllPacks();
  49.     GetAppParms(gAppName, &gAppResRef, &apParam);
  50.     bndlResource = GetAppIndResource('BNDL', 1, &err);
  51.     if (bndlResource)
  52.         gSignature = *(OSType *) (*bndlResource);
  53.  
  54. }
  55.  
  56. Boolean LoadMenus( short mBarNum )
  57. {
  58.     Handle    menuBar;
  59.     
  60.     menuBar = GetNewMBar(mBarNum);    
  61.     if (!menuBar)
  62.         return false;
  63.     SetMenuBar(menuBar);                    /* install menus */
  64.     DisposHandle(menuBar);
  65.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* add DA names to Apple menu */
  66.     DrawMenuBar();
  67.     return true;
  68. }
  69.  
  70. void TellUser(Str255 what, short errNum)
  71. {
  72.     short        itemHit;
  73.     unsigned char    errNumStr[256];
  74.     
  75.     SetCursor(&qd.arrow);
  76.     if (errNum) 
  77.         sprintf((char *) &errNumStr, "Significant number: %d", errNum);
  78.     else
  79.         sprintf((char *) &errNumStr, "No error number to report", 0);
  80.     ParamText(what, (ConstStr255Param) c2pstr((char *) errNumStr),nil,nil);
  81.     itemHit = NoteAlert(rUserAlert, nil);
  82. }
  83.  
  84. char *C2PStrCpy(char *Cstr, Str255 Pstr)
  85. {
  86.     short i, len = strlen(Cstr);
  87.     
  88.     for(i=len; i>0; i--) {
  89.         Pstr[i] = Cstr[i-1];
  90.     }
  91.     Pstr[i] = len;
  92.     
  93.     return( (char *) Pstr );
  94. }
  95.  
  96. Boolean GetOpenFSSpec(SFTypeList *types, short nTypes, FSSpec *fileSpec)
  97. {
  98.     StandardFileReply    openReply;
  99.     
  100.     StandardGetFile(nil, nTypes, *types, &openReply);
  101.     *fileSpec = openReply.sfFile;
  102.     return(openReply.sfGood);
  103. }
  104.  
  105. Boolean GetSaveFSSpec(SFTypeList *types, FSSpec *fileSpec)
  106. {
  107.     StandardFileReply    saveReply;
  108.     
  109.     StandardPutFile((ConstStr255Param) "\pSave as:",(ConstStr255Param) "", &saveReply);
  110.     
  111.     *fileSpec = saveReply.sfFile;
  112.     return (saveReply.sfGood);
  113. }
  114.  
  115.